#define USEMT       // 使用多线程

#include <cstdlib>
#include <print>
#include "PLFinder.h"

using namespace std;

int uiCallback(int n, bool iscol, int steps, unsigned int exhaNum)
{
    print("第 {:2} {}，解出 {:2} 格，递归数 {:8}。 按 q 键退出，回车键继续。", n, iscol ? "列" : "行", steps, exhaNum);
    return cin.get() == 'q';
}

int main(int argc, char* argv[])
{
	if (argc < 2)
	{
        println("Using: PLFinder filename [threadnum].");  // c++23 std::println
		return 1;
	}

#ifdef USEMT
    PLFinderMT plFinder(uiCallback);
#else
    PLFinderST plFinder(uiCallback);
#endif

    plFinder.needCallback = argc > 3 && argv[3][0] == '1';

    switch (plFinder.readFromFile(argv[1]))
    {
    case 1 :
        println("File Not Found Error.");
        return 1;
    case 2 ... 4 :
        println("File Context Error.");
		return 1;
    }

    int thrNum = 0;
    if (argc > 2) thrNum = atoi(argv[2]);

    int res = plFinder.exec(true, thrNum);
    plFinder.print(cout);

    println();
    if (res == 2) println("题目有错误!");
    println("Thread number {}.", plFinder.threadNum);
    println("Found {} grids. Used {} mSec.", plFinder.findSteps, plFinder.timeUsec/1000);
    println("最大递归：{}，次大递归：{}, 合计递归：{}", plFinder.exhaNum1st, plFinder.exhaNum2nd, plFinder.exhaSum);

	return 0;
}



